<html>
<head>
 
</head>
<body style="text-align=center;font-size:32px;">
<table align="center">
<tr><td><div id="problemNum" style='background-color:#999999;width:800;text-align:center;font-size:32px;'></div></td></tr>
<tr><td><div id="problemContent" style='word-wrap:break-word;background-color:#bbbbbb;width:800;text-align:left;font-size:Npx;'></div></td></tr>
<tr><td><div id="sum" style='word-wrap:break-word; color:#ffff22;font-size:48;background-color:#8855ff;width:800;text-align:center;'></div></td></tr>
<tr><td><div id="copyleft" style='word-wrap:break-word; color:#ffff22;font-size:18;background-color:#666666;width:800;text-align:right;'></div></td></tr>
<script language="javascript">
    //---------------------------------//
    // Project Euler 
    //
    // Author:thrombin
    //   Date:2015-12-14
    //---------------------------------//  
var p_order=17;//Problem Order
 
var problem='If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.\
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?\
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 \
(one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.';
 
 
//solve the problem
//==============编程思路简介================
//  总体用动态规划：先得到1000以内所有数的长度，然后求和
//=====================================
var N=1000;
var digit_len=[0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8];//1-19个特殊长度
//下面是整十的长度
digit_len[20]=6;
digit_len[30]=6;
digit_len[40]=5;
digit_len[50]=5;
digit_len[60]=5;
digit_len[70]=7;
digit_len[80]=6;
digit_len[90]=6;
 
for(var i=21;i<1000;i++){
     
    if(i<100){
        if(i%10==0)continue;
        digit_len[i]=digit_len[(i)%10]+digit_len[parseInt(i/10)*10];
    }
    else if(i%100==0){
        digit_len[i]=digit_len[parseInt(i/100)]+7;//整百的长度等于百位数的长度+7(hundred)
    }
    else{
        digit_len[i]=digit_len[parseInt(i/100)*100]+digit_len[i%100]+3;//100以后的非整百=整百+3(and)+一百以内的长度
    }
}
 
//求和
var sum=11;// one thousand
for(var i=1;i<1000;i++){
    sum+=digit_len[i];
}
 
//update browser
document.getElementById("problemNum").innerHTML="Project Euler-Problem "+p_order;
document.getElementById("problemContent").innerHTML=problem;
document.getElementById("sum").innerHTML="Answer:"+sum;
document.getElementById("copyleft").innerHTML="CopyLeft@Thrombin 2015";
</script>
</body>
</html>